<?php
/**
*
*/
class NewPlaceS1_model extends Model
{

	function __construct()
	{
		parent:: __construct();
	}
	public function newPlaceS1()
	{
		$error			= array();
		$PlaceName 		= $this->f->validate_input_text('/^[\w\'.-]{2,20}$/i',$_POST['PlaceName']);
		$PlaceAddress 	= $this->f->validate_input_text('/^[\w\'.-]{2,20}$/i',$_POST['PlaceAddress']);
		$CrossStreet 	= $this->f->validate_input_text('/^[\w\'.-]{2,20}$/i',$_POST['CrossStreet']);
		$City 			= $this->f->validate_input_text('/^[\w\'.-]{2,20}$/i',$_POST['City']);

		$PostalCode 	= $this->f->validate_input_text('/^[\w\'.-]{2,20}$/i',$_POST['PostalCode']);

		$PhoneNumber	= $this->f->validate_input_text('/^[\w\'.-]{2,20}$/i',$_POST['PhoneNumber']);
		$Website 		= $this->f->validate_url($_POST['Website']);
		$Facebook 		= $this->f->validate_url($_POST['Facebook']);
		$Twitter 		= $this->f->validate_url($_POST['Twitter']);
		$Description 	= $this->f->validate_input_text('/^[\w\'.-]{2,20}$/i',$_POST['Description']);

		$count 		= 0;
		if($PlaceName 		== false) $error[] = 'PlaceName';
		if($PlaceAddress 	== false) $error[] = 'PlaceAddress';
		if($CrossStreet 	== false) $error[] = 'CrossStreet';
		if($City 			== false) $error[] = 'City';

		if($PostalCode 		== false) $error[] = 'PostalCode';

		if($PhoneNumber 	== false) $error[] = 'PhoneNumber';
		if($Website 		== false) $error[] = 'Website';
		if($Facebook 		== false) $error[] = 'Facebook';
		if($Twitter			== false) $error[] = 'Twitter';
		if($Description 	== false) $error[] = 'Description';



		if(empty($error))
		{
			$q = $this->db->prepare(
							"INSERT INTO places (
								PlaceName,
								PlaceAddress,
								CrossStreet,
								City,
								PostalCode,
								PhoneNumber,
								Website,
								Facebook,
								Twitter,
								Description)
							VALUES (
								:PlaceName,
								:PlaceAddress,
								:CrossStreet,
								:City,
								:PostalCode,
								:PhoneNumber,
								:Website,
								:Facebook,
								:Twitter,
								:Description)");
			$value = $q->execute(array(
				':PlaceName' 		=> 	$PlaceName,
				':PlaceAddress'		=>	$PlaceAddress,
				':CrossStreet' 		=> 	$CrossStreet,
				':City'				=>	$City,

				':PostalCode' 		=> 	$PostalCode,

				':PhoneNumber'		=>	$PhoneNumber,
				':Website'			=>	$Website,
				':Facebook'			=>	$Facebook,
				':Twitter'			=>	$Twitter,
				':Description'		=>	$Description
			));

			$error[] =  $value;
		}
		echo json_encode($error);
	}
}
?>